package qldc.pm.qlktcsdldc.service.impl;

import java.util.Date;
import java.util.List;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;

import qldc.pm.qlktcsdldc.model.NguoiDung;
import qldc.pm.qlktcsdldc.service.base.NguoiDungLocalServiceBaseImpl;

/**
 * The implementation of the nguoi dung local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link qldc.pm.qlktcsdldc.service.NguoiDungLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see qldc.pm.qlktcsdldc.service.base.NguoiDungLocalServiceBaseImpl
 * @see qldc.pm.qlktcsdldc.service.NguoiDungLocalServiceUtil
 */
public class NguoiDungLocalServiceImpl extends NguoiDungLocalServiceBaseImpl {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never reference this interface directly. Always use {@link qldc.pm.qlktcsdldc.service.NguoiDungLocalServiceUtil} to access the nguoi dung local service.
     */
	public NguoiDung addNguoiDung(long nguoiDungId, String TenDangNhap, String HoVaTen, String SoCMND, long IDTinhThuongTru, long IDQuanHuyenThuongTru, long IDPhuongXaThuongTru, String DiaChiThuongTru,
			long IDQLKT_DanhMucSoBanNganh,int GioiTinh, long DanToc, String ChuThich, User user)
			throws PortalException, SystemException {

		// create a new instance of NguoiDung without saving it to the database
		NguoiDung NguoiDung = createNguoiDung(nguoiDungId);

		// set audit fields
		NguoiDung.setGroupId(user.getGroupId());
		NguoiDung.setCompanyId(user.getCompanyId());
		NguoiDung.setUserId(user.getUserId());
		NguoiDung.setUserName(user.getScreenName());
		NguoiDung.setCreateDate(new Date());

		// set other fields
		NguoiDung.setTenDangNhap(TenDangNhap);
		NguoiDung.setHoVaTen(HoVaTen);
		NguoiDung.setSoCMND(SoCMND);
		NguoiDung.setIDTinhThuongTru(IDTinhThuongTru);
		NguoiDung.setIDQuanHuyenThuongTru(IDQuanHuyenThuongTru);
		NguoiDung.setIDPhuongXaThuongTru(IDPhuongXaThuongTru);
		NguoiDung.setDiaChiThuongTru(DiaChiThuongTru);
		NguoiDung.setIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh);
		NguoiDung.setGioiTinh(GioiTinh);
		NguoiDung.setDanToc(DanToc);
		NguoiDung.setChuThich(ChuThich);
		NguoiDung.setDeleted(false);
		NguoiDung.setKichHoat(false);
		// save NguoiDung into the database
		return addNguoiDung(NguoiDung);
	}

	public NguoiDung updateNguoiDung(
		long NguoiDungId, String TenDangNhap, String HoVaTen, String SoCMND, long IDTinhThuongTru, long IDQuanHuyenThuongTru, long IDPhuongXaThuongTru, String DiaChiThuongTru,
		long IDQLKT_DanhMucSoBanNganh,int GioiTinh, long DanToc, String ChuThich, User user)
		throws PortalException, SystemException {

		// get the NguoiDung with the given NguoiDungId
		NguoiDung NguoiDung = getNguoiDung(NguoiDungId);

		// set audit fields
		NguoiDung.setGroupId(user.getGroupId());
		NguoiDung.setCompanyId(user.getCompanyId());
		NguoiDung.setUserId(user.getUserId());
		NguoiDung.setUserName(user.getScreenName());
		NguoiDung.setModifiedDate(new Date());

		// set other fields
		NguoiDung.setTenDangNhap(TenDangNhap);
		NguoiDung.setHoVaTen(HoVaTen);
		NguoiDung.setSoCMND(SoCMND);
		NguoiDung.setIDTinhThuongTru(IDTinhThuongTru);
		NguoiDung.setIDQuanHuyenThuongTru(IDQuanHuyenThuongTru);
		NguoiDung.setIDPhuongXaThuongTru(IDPhuongXaThuongTru);
		NguoiDung.setDiaChiThuongTru(DiaChiThuongTru);
		NguoiDung.setIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh);
		NguoiDung.setGioiTinh(GioiTinh);
		NguoiDung.setDanToc(DanToc);
		NguoiDung.setChuThich(ChuThich);
		// update the NguoiDung after set all needed parameters in to the
		// database
		return updateNguoiDung(NguoiDung);
	}
	public NguoiDung deleteNguoiDung(long NguoiDungId, User user)throws PortalException, SystemException {

		// get the NguoiDung with the given NguoiDungId
		NguoiDung NguoiDung = getNguoiDung(NguoiDungId);

		// set audit fields
		NguoiDung.setGroupId(user.getGroupId());
		NguoiDung.setCompanyId(user.getCompanyId());
		NguoiDung.setUserId(user.getUserId());
		NguoiDung.setUserName(user.getScreenName());
		NguoiDung.setModifiedDate(new Date());

		// set other fields
		NguoiDung.setDeleted(true);
		// update the NguoiDung after set all needed parameters in to the
		// database
		return updateNguoiDung(NguoiDung);
	}
	public NguoiDung kickHoatNguoiDung(long NguoiDungId, boolean kichHoat, User user)throws PortalException, SystemException {

		// get the NguoiDung with the given NguoiDungId
		NguoiDung NguoiDung = getNguoiDung(NguoiDungId);

		// set audit fields
		NguoiDung.setGroupId(user.getGroupId());
		NguoiDung.setCompanyId(user.getCompanyId());
		NguoiDung.setUserId(user.getUserId());
		NguoiDung.setUserName(user.getScreenName());
		NguoiDung.setModifiedDate(new Date());

		// set other fields
		NguoiDung.setKichHoat(kichHoat);
		// update the NguoiDung after set all needed parameters in to the
		// database
		return updateNguoiDung(NguoiDung);
	}
	
	public List<NguoiDung> searchNguoiDung( String tenSoBanNganh, String tenDangNhap, String hoVaTen)throws SystemException {
		return nguoiDungFinder.searchNguoiDung(tenSoBanNganh,tenDangNhap, hoVaTen );
	}

}
